package com.example.tired1.recyclerviewtest_xx14120200131;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    List<ArticleBean> list;
    Myadapter adapter;//声明适配器
    RecyclerView.LayoutManager layoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

        layoutManager=new LinearLayoutManager(MainActivity.this);
        recyclerView.setLayoutManager(layoutManager);//设置布局管理器

        list=getData();
        adapter=new Myadapter(MainActivity.this,list);//初始化适配器对象
        recyclerView.setAdapter(adapter);

    }

    private List<ArticleBean> getData() {
        List<ArticleBean> list;
        list = new ArrayList<ArticleBean>();
        ArticleBean article;
        article = new ArticleBean();
        article.setArticleId(0);
        article.setImgid(R.mipmap.f_angry);
        article.setTitle("title0");
        article.setDescription("description0");
        article.setTime("2016-12-22");
        list.add(article);


        article = new ArticleBean();
        article.setArticleId(1);
        article.setImgid(R.mipmap.f_cool);
        article.setTitle("title1");
        article.setDescription("description1");
        article.setTime("2016-12-23");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(2);
        article.setImgid(R.mipmap.f_crazy);
        article.setTitle("title2");
        article.setDescription("description2");
        article.setTime("2016-12-24");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(3);
        article.setImgid(R.mipmap.f_embarrassed);
        article.setTitle("title3");
        article.setDescription("description3");
        article.setTime("2016-12-25");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(4);
        article.setImgid(R.mipmap.f_huh);
        article.setTitle("title4");
        article.setDescription("description4");
        article.setTime("2016-12-26");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(5);
        article.setImgid(R.mipmap.f_love);
        article.setTitle("title5");
        article.setDescription("description5");
        article.setTime("2016-12-27");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(6);
        article.setImgid(R.mipmap.f_ninja);
        article.setTitle("title6");
        article.setDescription("description6");
        article.setTime("2016-12-28");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(7);
        article.setImgid(R.mipmap.f_ohhmy);
        article.setTitle("title7");
        article.setDescription("description7");
        article.setTime("2016-12-29");
        list.add(article);

        article = new ArticleBean();
        article.setArticleId(8);
        article.setImgid(R.mipmap.f_rolleyes);
        article.setTitle("title8");
        article.setDescription("description8");
        article.setTime("2016-12-21");
        list.add(article);
        return list;
    }
}
